<template>
    <div class="portlet box blue">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gift"></i>通行证查询</div>
            <div class="tools">
                <a href="javascript:;" class="collapse" data-original-title="" title=""></a>
            </div>
        </div>
        <div class="portlet-body form">
            <!-- BEGIN FORM-->
            <form action="#" class="form-horizontal">
                <div class="form-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">团队通行证</label>
                                <div class="col-md-9">
                                    <passport-select ref="teamSelect" :types="['TEAM']" @PassportSelectChanged="TeamSelectChanged"></passport-select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">团队名称</label>
                                <div class="col-md-9">
                                    <el-input placeholder="请输入您想查询的团队名称" v-model="condition.Name" clearable></el-input>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">领队姓名</label>
                                <div class="col-md-9">
                                    <passport-select ref="leaderSelect" @PassportSelectChanged="LeaderSelectChanged"></passport-select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">团队成员姓名</label>
                                <div class="col-md-9">
                                    <passport-select ref="memberSelect" @PassportSelectChanged="MemberSelectChanged"></passport-select>
                                </div>
                            </div> 
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">团队人数</label>
                                <div class="col-md-9">
                                    <el-input-number v-model="condition.MemberCount0" controls-position="right" :min="1" :max="100" style="width:48%"></el-input-number>
                                    <span style="font-size:12px;">至</span>
                                    <el-input-number v-model="condition.MemberCount1" controls-position="right" :min="1" :max="100" style="width:48%"></el-input-number>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">创建日期</label>
                                <div class="col-md-9">
                                    <el-date-picker v-model="createTimeRange" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions" style="width:100%"></el-date-picker>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-actions">
                    <div class="row">
                        <div class="col-md-12 pull-right">
                            <div style="float:right;">
                                <button type="button" class="btn green" @click="exportTeams()">导出团队列表</button>
                                <button type="button" class="btn green" @click="query()">查询通行证</button>
                                <button type="button" class="btn default" @click="clear()">清空条件</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- END FORM-->
        </div>
    </div>
</template>

<script>


import {GetPickerShortcuts} from 'web/utils.js';
import Locations from 'assets/locations.js';
import PassportSelect from 'components/passport_select.vue';

export default {
    props: {
        'data': {
            type: Object,
            default: null
        },
    },
    components: {
        PassportSelect
    },
    data() {
        return {
            condition: { 
                MemberCount0: 1,
                MemberCount1: 100
            },
            createTimeRange: null,
            pickerOptions: GetPickerShortcuts(),
        }
    },
    watch: {
        'data': {
            handler: function(value){
                this.condition = value;
            },
            deep: true
        },
    },
    mounted() {
        this.query();
    },
    methods: {
        query() {
            // 将时间范围分解到condition中
            let _condition = Object.assign({}, this.condition);
            if (this.createTimeRange) {
                _condition.CreateTime0 = this.createTimeRange[0];
                _condition.CreateTime1 = this.createTimeRange[1];
            }
            this.$emit('getTeamCondition', _condition);
        }, 

        TeamSelectChanged(teamdIds) {
            this.condition.TeamIds = teamdIds;
        },

        LeaderSelectChanged(userIds) {
            this.condition.LeaderIds = userIds;
        },

        MemberSelectChanged(userIds) {
            this.condition.MemberIds = userIds;
        },

        clear() {
            this.condition = {
                MemberCount0: 1,
                MemberCount1: 100
            }; 
            this.createTimeRange = null;  
            this.$refs.teamSelect.clear();       
            this.$refs.leaderSelect.clear();       
            this.$refs.memberSelect.clear();       
        },

        exportTeams() {
            this.query();            
            this.$PassportService.ExportTeams(this.condition);
        }         
    }
}
</script>

<style>

</style>
